package seguranca.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import br.com.sgc.permissao.Role;

public class RoleConverter implements Converter{

	@Override
	public Object getAsObject(FacesContext context, UIComponent arg1, String value) {
		Role role = null;
		for(Role r: Role.values()) {
			if(r.name().equals(value)){
				role = r;
			}
		}
		return role;
	}

	@Override
	public String getAsString(FacesContext context, UIComponent arg1, Object value) {
		return ((Role)value).name();
	}

}
